home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 15 / macformat_15.iso / C de cerca / Codewarrior Lite / MacOS Support / Headers / ANSI Headers / math.h < prev    next >
Text File  |  1995-12-29  |  15KB  |  558 lines

  1. /* math.h standard header */
  2. #ifdef __MWERKS__
  3.  
  4. #ifndef __MATH__
  5. #define    __MATH__
  6.  
  7. #if defined(__FP__) && defined(__MC68K__) && defined(__cplusplus)
  8. #error Cannot include both <fp.h> and <math.h>, these headers are incompatible
  9. #endif
  10.  
  11. #pragma options align=mac68k
  12.  
  13. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  14. #pragma import on
  15. #endif
  16.  
  17.         /* common macros */
  18. #define _PI            pi
  19. #define HUGE_VAL    __inf()
  20.  
  21.         /*
  22.          *    Set the following define to 1 to force the ANSI math header to inline FPU calls
  23.          *    whenever possible.  This behaviour is not ANSI compatible, so should be used with
  24.          *    care.
  25.          *    NB: on 680x0 macs, using inlines in conjunction with 8byte doubles will not work
  26.          *    correctly.
  27.          */
  28. #if !defined(_INLINE_FPU_CALLS_) && __MC68K__
  29. #define _INLINE_FPU_CALLS_ 0
  30. #endif
  31.  
  32.         /* common type definitions */
  33. typedef union {
  34.     unsigned short _W[5];
  35.     float _F;
  36.     double _D;
  37.     long double _L;
  38.     } _Dconst;
  39.  
  40. #ifndef _YVALS
  41. #include <yvals.h>
  42. #endif
  43.  
  44.         /* function prototype declarations (common to both 68K and PPC) */
  45. _C_LIB_DECL
  46.         /* float declarations */
  47. float cosf(float);
  48. float sinf(float);
  49. float tanf(float);
  50. float acosf(float);
  51. float asinf(float);
  52. float atanf(float);
  53. float atan2f(float, float);
  54. float coshf(float);
  55. float sinhf(float);
  56. float tanhf(float);
  57. float expf(float);
  58. float frexpf(float, int *);
  59. float ldexpf(float, int);
  60. float logf(float);
  61. float log10f(float);
  62. float modff(float, float*);
  63. float fabsf(float);
  64. float powf(float, float);
  65. float sqrtf(float);
  66. float ceilf(float);
  67. float floorf(float);
  68. float fmodf(float, float);
  69. _END_C_LIB_DECL
  70.  
  71. #if __POWERPC__
  72.  
  73.         /* constants */
  74. extern const double pi;
  75.         /* function prototypes */
  76. _C_LIB_DECL
  77.         /* infinity function */
  78. double __inf ( void );
  79.         /* double declarations */
  80. double cos(double);
  81. double sin(double);
  82. double tan(double);
  83. double acos(double);
  84. double asin(double);
  85. double atan(double);
  86. double atan2(double, double);
  87. double cosh(double);
  88. double sinh(double);
  89. double tanh(double);
  90. double exp(double);
  91. double frexp(double, int *);
  92. double ldexp(double, int);
  93. double log(double);
  94. double log10(double);
  95. double modf(double, double *);
  96. double pow(double, double);
  97. double sqrt(double);
  98. double ceil(double);
  99. double floor(double);
  100. double fmod(double, double);
  101. _END_C_LIB_DECL
  102.  
  103. #ifdef __cplusplus
  104.         /* double inlines, for C++ */
  105. inline double fabs(double x)    { return __fabs(x); }
  106. #else
  107.         /* double macro overrides, for C */
  108. double fabs(double);
  109. #define fabs(x)            __fabs(x)
  110. #endif
  111.  
  112. #else    /* !__POWERPC__ */
  113.  
  114.         /* constants */
  115. extern const long double pi;
  116.         /* function prototypes */
  117. _C_LIB_DECL
  118.         /* infinity function */
  119. long double __inf ( void );
  120.         /* long double declarations */
  121. long double cosl(long double);
  122. long double sinl(long double);
  123. long double tanl(long double);
  124. long double acosl(long double);
  125. long double asinl(long double);
  126. long double atanl(long double);
  127. long double atan2l(long double, long double);
  128. long double coshl(long double);
  129. long double sinhl(long double);
  130. long double tanhl(long double);
  131. long double expl(long double);
  132. long double frexpl(long double, int *);
  133. long double ldexpl(long double, int);
  134. long double logl(long double);
  135. long double log10l(long double);
  136. long double modfl(long double, long double *);
  137. long double fabsl(long double);
  138. long double powl(long double, long double);
  139. long double sqrtl(long double);
  140. long double ceill(long double);
  141. long double floorl(long double);
  142. long double fmodl(long double, long double);
  143.         /* internally used functions */
  144. double _Sinh(double, double);
  145. double _Cosh(double, double);
  146. long double _LCosh(long double, long double);
  147. long double _LSinh(long double, long double);
  148. _END_C_LIB_DECL
  149.  
  150.         /* double macro overrides */
  151. #if _INLINE_FPU_CALLS_ && __MC68881__
  152. _C_LIB_DECL
  153.         /* call the FPU directly (NOT ANSI COMPATIBLE) */
  154. long double _fpucos(long double:__FP0):__FP0 = { 0xF200,0x001D };
  155. long double _fpusin(long double:__FP0):__FP0 = { 0xF200,0x000E };
  156. long double _fputan(long double:__FP0):__FP0 = { 0xF200,0x000F };
  157. long double _fpuacos(long double:__FP0):__FP0 = { 0xF200,0x001C };
  158. long double _fpuasin(long double:__FP0):__FP0 = { 0xF200,0x000C };
  159. long double _fpuatan(long double:__FP0):__FP0 = { 0xF200,0x000A };
  160. long double _fpucosh(long double:__FP0):__FP0 = { 0xF200,0x0019 };
  161. long double _fpusinh(long double:__FP0):__FP0 = { 0xF200,0x0002 };
  162. long double _fputanh(long double:__FP0):__FP0 = { 0xF200,0x0009 };
  163. long double _fpuexp(long double:__FP0):__FP0 = { 0xF200,0x0010 };
  164. long double _fpuldexp(long double:__FP0,long:__D0):__FP0 = { 0xF200,0x4026 };
  165. long double _fpulog(long double:__FP0):__FP0 = { 0xF200,0x0014 };
  166. long double _fpulog10(long double:__FP0):__FP0 = { 0xF200,0x0015 };
  167. long double _fpufabs(long double:__FP0):__FP0 = { 0xF200,0x0018 };
  168. long double _fpusqrt(long double:__FP0):__FP0 = { 0xF200,0x0004 };
  169. long double _fpufmod(long double:__FP0,long double:__FP1):__FP0 = { 0xF200,0x0421 };
  170. _END_C_LIB_DECL
  171.  
  172. #ifdef __cplusplus
  173.         /* double inlines, for C++ */
  174. inline double cos(double x)                { return (_fpucos(x)); }
  175. inline double sin(double x)                { return (_fpusin(x)); }
  176. inline double tan(double x)                { return (_fputan(x)); }
  177. inline double acos(double x)            { return (_fpuacos(x)); }
  178. inline double asin(double x)            { return (_fpuasin(x)); }
  179. inline double atan(double x)            { return (_fpuatan(x)); }
  180. inline double cosh(double x)            { return (_fpucosh(x)); }
  181. inline double sinh(double x)            { return (_fpusinh(x)); }
  182. inline double tanh(double x)            { return (_fputanh(x)); }
  183. inline double exp(double x)                { return (_fpuexp(x)); }
  184. inline double ldexp(double x, int y)    { return (_fpuldexp(x,y)); }
  185. inline double log(double x)                { return (_fpulog(x)); }
  186. inline double log10(double x)            { return (_fpulog10(x)); }
  187. inline double fabs(double x)            { return (_fpufabs(x)); }
  188. inline double sqrt(double x)            { return (_fpusqrt(x)); }
  189. inline double fmod(double x, double y)    { return (_fpufmod(x,y)); }
  190. #else
  191.         /* double macro overrides, for C */
  192. double cos(double);
  193. double sin(double);
  194. double tan(double);
  195. double acos(double);
  196. double asin(double);
  197. double atan(double);
  198. double cosh(double);
  199. double sinh(double);
  200. double tanh(double);
  201. double exp(double);
  202. double ldexp(double, int);
  203. double log(double);
  204. double log10(double);
  205. double fabs(double);
  206. double sqrt(double);
  207. double fmod(double, double);
  208. #define cos(x)            _fpucos(x)
  209. #define sin(x)            _fpusin(x)
  210. #define tan(x)            _fputan(x)
  211. #define acos(x)            _fpuacos(x)
  212. #define asin(x)            _fpuasin(x)
  213. #define atan(x)            _fpuatan(x)
  214. #define cosh(x)            _fpucosh(x)
  215. #define sinh(x)            _fpusinh(x)
  216. #define tanh(x)            _fputanh(x)
  217. #define exp(x)            _fpuexp(x)
  218. #define ldexp(x,n)        _fpuldexp(x,n)
  219. #define log(x)            _fpulog(x)
  220. #define log10(x)        _fpulog10(x)
  221. #define fabs(x)            _fpufabs(x)
  222. #define sqrt(x)            _fpusqrt(x)
  223. #define fmod(x,y)        _fpufmod(x,y)
  224. #endif
  225.  
  226. #elif __option(IEEEdoubles)
  227.  
  228. _C_LIB_DECL
  229.         /* ANSI compatible double overrides */
  230. double cosd(double);
  231. double sind(double);
  232. double tand(double);
  233. double acosd(double);
  234. double asind(double);
  235. double atand(double);
  236. double coshd(double);
  237. double sinhd(double);
  238. double tanhd(double);
  239. double expd(double);
  240. double ldexpd(double, int);
  241. double logd(double);
  242. double log10d(double);
  243. double fabsd(double);
  244. double sqrtd(double);
  245. double fmodd(double, double);
  246. _END_C_LIB_DECL
  247.  
  248. #ifdef __cplusplus
  249.         /* double inlines, for C++ */
  250. inline double cos(double x)                { return (cosd(x)); }
  251. inline double sin(double x)                { return (sind(x)); }
  252. inline double tan(double x)                { return (tand(x)); }
  253. inline double acos(double x)            { return (acosd(x)); }
  254. inline double asin(double x)            { return (asind(x)); }
  255. inline double atan(double x)            { return (atand(x)); }
  256. inline double cosh(double x)            { return (coshd(x)); }
  257. inline double sinh(double x)            { return (sinhd(x)); }
  258. inline double tanh(double x)            { return (tanhd(x)); }
  259. inline double exp(double x)                { return (expd(x)); }
  260. inline double ldexp(double x, int y)    { return (ldexpd(x,y)); }
  261. inline double log(double x)                { return (logd(x)); }
  262. inline double log10(double x)            { return (log10d(x)); }
  263. inline double fabs(double x)            { return (fabsd(x)); }
  264. inline double sqrt(double x)            { return (sqrtd(x)); }
  265. inline double fmod(double x, double y)    { return (fmodd(x,y)); }
  266. #else
  267.         /* double macro overrides, for C */
  268. double cos(double);
  269. double sin(double);
  270. double tan(double);
  271. double acos(double);
  272. double asin(double);
  273. double atan(double);
  274. double cosh(double);
  275. double sinh(double);
  276. double tanh(double);
  277. double exp(double);
  278. double ldexp(double, int);
  279. double log(double);
  280. double log10(double);
  281. double fabs(double);
  282. double sqrt(double);
  283. double fmod(double, double);
  284. #define cos(x)            cosd(x)
  285. #define sin(x)            sind(x)
  286. #define tan(x)            tand(x)
  287. #define acos(x)            acosd(x)
  288. #define asin(x)            asind(x)
  289. #define atan(x)            atand(x)
  290. #define cosh(x)            coshd(x)
  291. #define sinh(x)            sinhd(x)
  292. #define tanh(x)            tanhd(x)
  293. #define exp(x)            expd(x)
  294. #define ldexp(x,n)        ldexpd(x,n)
  295. #define log(x)            logd(x)
  296. #define log10(x)        log10d(x)
  297. #define fabs(x)            fabsd(x)
  298. #define sqrt(x)            sqrtd(x)
  299. #define fmod(x,y)        fmodd(x,y)
  300. #endif
  301.  
  302. #else    /* we don't have FPU inlines, nor do we have 8 byte IEEE Doubles */
  303.  
  304. _C_LIB_DECL
  305. double cos(double);
  306. double sin(double);
  307. double tan(double);
  308. double acos(double);
  309. double asin(double);
  310. double atan(double);
  311. double cosh(double);
  312. double sinh(double);
  313. double tanh(double);
  314. double exp(double);
  315. double ldexp(double, int);
  316. double log(double);
  317. double log10(double);
  318. double fabs(double);
  319. double sqrt(double);
  320. double fmod(double, double);
  321. _END_C_LIB_DECL
  322.  
  323. #endif    /* _INLINE_FPU_CALLS_ && __MC68881__ */
  324.  
  325. #if __option(IEEEdoubles)
  326.  
  327. _C_LIB_DECL
  328. double atan2d(double, double);
  329. double frexpd(double, int *);
  330. double modfd(double, double *);
  331. double powd(double, double);
  332. double ceild(double);
  333. double floord(double);
  334. _END_C_LIB_DECL
  335.  
  336. #ifdef __cplusplus
  337.         /* double inlines, for C++ */
  338. inline double atan2(double x, double y)            { return (atan2d(x,y)); }
  339. inline double frexp(double x, int *exp)            { return (frexpd(x,exp)); }
  340. inline double modf(double x, double *iptr)        { return (modfd(x,iptr)); }
  341. inline double pow(double x, double y)            { return (powd(x,y)); }
  342. inline double ceil(double x)                    { return (ceild(x)); }
  343. inline double floor(double x)                    { return (floord(x)); }
  344. #else
  345.         /* double macro overrides, for C */
  346. double atan2(double, double);
  347. double frexp(double, int *);
  348. double modf(double, double *);
  349. double pow(double, double);
  350. double ceil(double);
  351. double floor(double);
  352. #define atan2(x,y)        atan2d(x,y)
  353. #define frexp(x,exp)    frexpd(x,exp)
  354. #define modf(x,iptr)    modfd(x,iptr)
  355. #define pow(x,y)        powd(x,y)
  356. #define ceil(x)            ceild(x)
  357. #define floor(x)        floord(x)
  358. #endif
  359.  
  360. #else
  361.  
  362. _C_LIB_DECL
  363. double atan2(double, double);
  364. double frexp(double, int *);
  365. double modf(double, double *);
  366. double pow(double, double);
  367. double ceil(double);
  368. double floor(double);
  369. _END_C_LIB_DECL
  370.  
  371. #endif
  372.  
  373. #endif    /* __POWERPC__ */
  374.  
  375. #if __CFM68K__ && __USING_IMPORTED_ANSI__
  376. #pragma import reset
  377. #endif
  378.  
  379. #pragma options align=reset
  380.  
  381. #endif    /* __MATH__ */
  382.  
  383. #else    /* !__MWERKS__ */
  384.  
  385. #ifndef _MATH
  386. #define _MATH
  387. #include <yvals.h>
  388.         /* macros */
  389. #define HUGE_VAL    _Hugeval._D
  390.         /* type definitions */
  391. #if defined(__CENTERLINE__)
  392. typedef struct {
  393. #else
  394. typedef union {
  395. #endif
  396.     unsigned short _W[5];
  397.     float _F;
  398.     double _D;
  399.     long double _L;
  400.     } _Dconst;
  401. _C_LIB_DECL
  402.         /* double declarations */
  403. double acos(double);
  404. double asin(double);
  405. double atan(double);
  406. double atan2(double, double);
  407. double ceil(double);
  408. double exp(double);
  409. double fabs(double);
  410. double floor(double);
  411. double fmod(double, double);
  412. double frexp(double, int *);
  413. double ldexp(double, int);
  414. double modf(double, double *);
  415. double pow(double, double);
  416. double sqrt(double);
  417. double tan(double);
  418. double tanh(double);
  419. double _Cosh(double, double);
  420. double _Log(double, int);
  421. double _Sin(double, unsigned int);
  422. double _Sinh(double, double);
  423. extern const _Dconst _Hugeval;
  424.         /* float declarations */
  425. float acosf(float);
  426. float asinf(float);
  427. float atanf(float);
  428. float atan2f(float, float);
  429. float ceilf(float);
  430. float expf(float);
  431. float fabsf(float);
  432. float floorf(float);
  433. float fmodf(float, float);
  434. float frexpf(float, int *);
  435. float ldexpf(float, int);
  436. float modff(float, float *);
  437. float powf(float, float);
  438. float sqrtf(float);
  439. float tanf(float);
  440. float tanhf(float);
  441. float _FCosh(float, float);
  442. float _FLog(float, int);
  443. float _FSin(float, unsigned int);
  444. float _FSinh(float, float);
  445.         /* long double declarations */
  446. long double acosl(long double);
  447. long double asinl(long double);
  448. long double atanl(long double);
  449. long double atan2l(long double, long double);
  450. long double ceill(long double);
  451. long double expl(long double);
  452. long double fabsl(long double);
  453. long double floorl(long double);
  454. long double fmodl(long double, long double);
  455. long double frexpl(long double, int *);
  456. long double ldexpl(long double, int);
  457. long double modfl(long double, long double *);
  458. long double powl(long double, long double);
  459. long double sqrtl(long double);
  460. long double tanl(long double);
  461. long double tanhl(long double);
  462. long double _LCosh(long double, long double);
  463. long double _LLog(long double, int);
  464. long double _LSin(long double, unsigned int);
  465. long double _LSinh(long double, long double);
  466. _END_C_LIB_DECL
  467. #ifdef __cplusplus
  468.         /* double inlines, for C++ */
  469. inline double cos(double _X)
  470.     {return (_Sin(_X, 1)); }
  471. inline double cosh(double _X)
  472.     {return (_Cosh(_X, 1)); }
  473. inline double log(double _X)
  474.     {return (_Log(_X, 0)); }
  475. inline double log10(double _X)
  476.     {return (_Log(_X, 1)); }
  477. inline double sin(double _X)
  478.     {return (_Sin(_X, 0)); }
  479. inline double sinh(double _X)
  480.     {return (_Sinh(_X, 1)); }
  481.         /* float inlines, for C++ */
  482. inline float cosf(float _X)
  483.     {return (_FSin(_X, 1)); }
  484. inline float coshf(float _X)
  485.     {return (_FCosh(_X, 1)); }
  486. inline float logf(float _X)
  487.     {return (_FLog(_X, 0)); }
  488. inline float log10f(float _X)
  489.     {return (_FLog(_X, 1)); }
  490. inline float sinf(float _X)
  491.     {return (_FSin(_X, 0)); }
  492. inline float sinhf(float _X)
  493.     {return (_FSinh(_X, 1)); }
  494.         /* long double inlines, for C++ */
  495. inline long double cosl(long double _X)
  496.     {return (_LSin(_X, 1)); }
  497. inline long double coshl(long double _X)
  498.     {return (_LCosh(_X, 1)); }
  499. inline long double logl(long double _X)
  500.     {return (_LLog(_X, 0)); }
  501. inline long double log10l(long double _X)
  502.     {return (_LLog(_X, 1)); }
  503. inline long double sinl(long double _X)
  504.     {return (_LSin(_X, 0)); }
  505. inline long double sinhl(long double _X)
  506.     {return (_LSinh(_X, 1)); }
  507. #else
  508.         /* double macro overrides, for C */
  509. double cos(double);
  510. double cosh(double);
  511. double log(double);
  512. double log10(double);
  513. double sin(double);
  514. double sinh(double);
  515. #define cos(x)        _Sin(x, 1)
  516. #define cosh(x)        _Cosh(x, 1)
  517. #define log(x)        _Log(x, 0)
  518. #define log10(x)    _Log(x, 1)
  519. #define sin(x)        _Sin(x, 0)
  520. #define sinh(x)        _Sinh(x, 1)
  521.         /* float macro overrides, for C */
  522. float cosf(float);
  523. float coshf(float);
  524. float logf(float);
  525. float log10f(float);
  526. float sinf(float);
  527. float sinhf(float);
  528. #define cosf(x)        _FSin(x, 1)
  529. #define coshf(x)    _FCosh(x, 1)
  530. #define logf(x)        _FLog(x, 0)
  531. #define log10f(x)    _FLog(x, 1)
  532. #define sinf(x)        _FSin(x, 0)
  533. #define sinhf(x)    _FSinh(x, 1)
  534.         /* long double macro overrides, for C */
  535. long double cosl(long double);
  536. long double coshl(long double);
  537. long double logl(long double);
  538. long double log10l(long double);
  539. long double sinl(long double);
  540. long double sinhl(long double);
  541. #define cosl(x)        _LSin(x, 1)
  542. #define coshl(x)    _LCosh(x, 1)
  543. #define logl(x)        _LLog(x, 0)
  544. #define log10l(x)    _LLog(x, 1)
  545. #define sinl(x)        _LSin(x, 0)
  546. #define sinhl(x)    _LSinh(x, 1)
  547. #endif
  548.  
  549. #endif
  550.  
  551. #endif    /* __MWERKS__ */
  552.  
  553. /*
  554.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  555.  * Consult your license regarding permissions and restrictions.
  556.  */
  557.  
  558.